import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  OneToMany,
  CreateDateColumn,
  UpdateDateColumn,
  JoinColumn,
} from 'typeorm';
import { User } from './user.entity';
import { FavoriteVideo } from './favorite-videos.entity';

@Entity('favorites')
export class Favorite {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: 'varchar',
    length: 50,
    comment: '收藏夹名称',
  })
  name: string;

  @Column({
    type: 'varchar',
    length: 200,
    nullable: true,
    comment: '收藏夹描述',
  })
  description: string;

  @Column({
    type: 'tinyint',
    width: 1,
    default: 0,
    comment: '是否为默认收藏夹 0-否 1-是',
  })
  is_default: number;

  @Column({
    type: 'tinyint',
    width: 1,
    default: 0,
    comment: '是否公开 0-私密 1-公开',
  })
  is_public: number;

  @ManyToOne(() => User, (user) => user.favorites)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @OneToMany(() => FavoriteVideo, (favoriteVideo) => favoriteVideo.favorite)
  favoriteVideos: FavoriteVideo[];

  @Column({ default: 0 })
  video_count: number;

  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
  })
  created_at: Date;

  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
  })
  updated_at: Date;

  @Column({
    type: 'tinyint',
    width: 1,
    default: 0,
    comment: '是否删除 0-否 1-是',
  })
  is_delete: number;
}
